package com.qzw.study.circledepend;

import org.springframework.aop.scope.ScopedObject;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.Scope;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

/**
 * @author ：quziwei
 * @date ：2020/8/13 1:26
 * @description：自己构建的Bean工厂后置处理器
 * 通过它来修改bean定义的属性
 */
//@Component
public class SelfBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		BeanDefinition person = beanFactory.getBeanDefinition("person");
		person.setFactoryBeanName("123");
	}
}

@Component("selfBeanDefinitionRegistryPostProcessor")
class SelfBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor{

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
		GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
		beanDefinition.setBeanClass(A.class);
		beanDefinition.setLazyInit(false);
		beanDefinition.setAutowireCandidate(true);
		beanDefinition.setScope("singleton");
		beanDefinition.setBeanClassName(A.class.getName());
		beanDefinition.setFactoryBeanName("self");
		registry.registerBeanDefinition("self",beanDefinition);
	}

	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

	}
}
